<template>
  <div
    v-show="visible"
    class="zuicoolConfirm"
    @touchmove.prevent
    @click="hide"
  >
    <div class="board" :style="{marginTop: `${topOffset}px`}" @click.stop>
      <button class="close" @click="hide"/>

      <div class="kudou" :class="[`style${type}`]"/>

      <div class="notification">
        <slot name="title">
          <p class="defaultTitle" v-html="title"/>
        </slot>

        <slot name="content">
          <p class="defaultContent" v-html="content"/>
        </slot>
      </div>

      <div class="buttonsGroup">
        <slot name="button">
          <button class="buttonItem" @click="cancel">
            {{cancelLabel}}
          </button>

          <button class="buttonItem" @click="confirm">
            {{confirmLabel}}
          </button>
        </slot>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "zuicool-confirm",

    props: {
      // style is reserved attribute
      type: {
        type: [String, Number],
      },
      title: {
        type: String,
        default: ''
      },
      content: {
        type: String,
        default: ''
      },
      confirmLabel: {
        type: String,
        default: '确定'
      },
      cancelLabel: {
        type: String,
        default: '取消'
      },
      show: {
        type: Boolean,
        default: false
      },
      topOffset: {
        type: Number,
        default: -20
      }
    },

    data() {
      return {
        visible: this.show
      }
    },

    watch: {
      show(val) {
        this.visible = val
      }
    },

    methods: {
      confirm() {
        this.$emit('confirm');
        this.hide()
      },

      cancel() {
        this.$emit('cancel');
        this.hide()
      },

      hide() {
        this.$emit('hide');
        this.$emit('update:show', false);
      }
    }
  }
</script>

<style lang="less" scoped>
  .zuicoolConfirm {
    z-index: 98;

    position: fixed;
    top: 0;
    left: 0;

    width: 100%;
    height: 100%;

    background-color: rgba(0, 0, 0, .7);
  }

  .close {
    z-index: 1;
    display: inline-block;

    position: absolute;
    right: 5px;
    top: 5px;

    outline: none;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;

    background: url("./cross.png") rgba(255, 255, 255, .8) center / 50% no-repeat;
  }

  .kudou {
    z-index: 1;
    display: block;

    position: relative;

    margin: -30px auto 0;
    border-radius: 50%;
    width: 92px;
    height: 92px;

    background-image: linear-gradient(to bottom, #fff, #f3a49b);
    &:before {
      content: '';
      display: inline-block;

      position: absolute;
      top: -10px;
      left: 11px;

      width: 70px;
      height: 100%;

      background: url('./kudou.png') center / contain no-repeat;
    }
    &.style2:before {
      background-image: url('./kudou2.png');
    }
  }

  @borderRadius: 5px;
  .board {
    position: absolute;
    top: 50%;
    left: 50%;

    box-sizing: border-box;
    margin-left: -133px;
    border-radius: @borderRadius;
    padding: 0 25px 22px;
    width: 266px;

    font-size: 16px;
    text-align: center;

    background-color: #fff;
    transform: translateY(-50%);
    &:before {
      content: '';
      display: inline-block;

      position: absolute;
      left: 0;
      top: 0;

      border-radius: @borderRadius;
      border-bottom-right-radius: 135px 50px;
      border-bottom-left-radius: 135px 50px;
      width: 100%;
      height: 110px;

      background-color: #ff4e3b;
    }
  }

  .notification {
    z-index: 1;

    position: relative;

    margin-top: 10px;
    min-height: 85px;

    text-align: center;
    line-height: 22px;

    > p:last-child {
      margin-top: 38px;
    }
  }

  .defaultTitle {
    min-height: 20px;
    font-size: 20px;
    color: #fff;
    font-weight: bolder;
  }

  .defaultContent {
    color: #df4f43;
  }

  .buttonsGroup {
    margin-top: 30px;
  }

  .buttonItem {
    border-radius: 18px;
    width: 102px;
    height: 36px;

    box-shadow: 1px 1px 10px 0 #aaa;
    color: #666;
    font-size: 16px;
    &:last-child {
      float: right;
      color: #fff;
      background-image: linear-gradient(to right, #FE8353, #FF523D);
    }
  }
</style>
